package com.mickey.dao;

import com.mickey.domain.MiaoshaOrder;
import com.mickey.domain.OrderInfo;
import org.apache.ibatis.annotations.*;

@Mapper
public interface OrderDao {

    @Select("select * from miaosha_order where user_id = #{userId} and goods_id = #{goodsId}")
    MiaoshaOrder getMiaoshaOrderByUserIdGoodsId(@Param("userId") Long userId, @Param("goodsId") long goodsId);

    /**
     * 插入订单返回ID
     * @param orderInfo
     * @return
     */
    @Insert("insert into order_info (user_id, goods_id, delivery_addr_id, goods_name, goods_count, goods_price, order_channel, status, create_date, pay_date) VALUES " +
            "(#{userId}, #{goodsId}, #{deliveryAddrId}, #{goodsName}, #{goodsCount}, #{goodsPrice}, #{orderChannel}, #{status}, #{createDate}, #{payDate})")
    @SelectKey(keyColumn = "id",keyProperty = "id",resultType = long.class,before = false,statement ="select last_insert_id()")
    long insert(OrderInfo orderInfo);

    /**
     * 插入秒杀订单
     * @param miaoshaOrder
     * @return
     */
    @Insert("INSERT INTO miaosha_order (user_id, order_id, goods_id) VALUES ( #{userId}, #{orderId}, #{goodsId})")
    int insertMiaoshaOrder(MiaoshaOrder miaoshaOrder);

    /**
     * 查询订单详情
     * @param orderId
     * @return
     */
    @Select("select * from order_info where id = #{orderId}")
    OrderInfo getOrderById(@Param("orderId") long orderId);
}
